package org.jsola.hr.constant.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.PunchStatus;

/**
 *【打卡状态】excel导入导出时字段值转换
 * @author wangxuezheng
 */
public class PunchStatusConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        PunchStatus punchStatus = PunchStatus.findByDesc(cellData.getStringValue());
        if (punchStatus == null) {
            return SafeKit.getInteger(cellData.getStringValue());
        }
        return punchStatus.getValue();
    }

    @Override
    public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        PunchStatus punchStatus = PunchStatus.find(value);
        if (punchStatus == null) {
            return new CellData(value);
        }
        return new CellData(punchStatus.getDesc());
    }
}
